//
//  HEIMGroupViewController.m
//  HealthElderly
//
//  Created by 吴欧 on 2021/11/22.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEIMGroupViewController.h"
#import "HEIMTextCell.h"
#import "HEIMInfoEntity.h"
#import "HEIMForward.h"
#import "HEActivityHeader.h"
#import "HEIMImageViewCell.h"
#import "HEIMAudioCell.h"
#import "HEMediaManager.h"
#import "HEChatManager.h"
#import "HEIMConsulReportCell.h"
#import "HEConsulReportViewController.h"
#import "HETeamModel.h"
#import "HEDocImMsgModel.h"
#import "HEIMProductCell.h"
#import "HEGoodsDetailsViewController.h"
#import "HEItemBtnView.h"
#import "HEDoctorMainPageViewController.h"
#import "HEIMCommentCell.h"
#import "HEConsulCommentViewController.h"
#import "HEATPersonListViewController.h"
#import "HEChatBar.h"
#import "HEIMGroupMemberModel.h"
#import "HEIMSystemMessageCell.h"
#import "HEIMRoomInAndoutCell.h"
#import "HEIMNotificationViewController.h"
#import "HEIMGroupDetailsViewController.h"
#import "HEIMGroupNotifModel.h"

@interface HEIMGroupViewController ()<UITableViewDelegate, UITableViewDataSource, HEIMMessageCellDelegate, HESocketManagerDelegate, HEChatBarDelegate, HEChatManagerDelegate, HEChatBarDelegate>

@property (nonatomic, strong) GDTableView *tableView;
@property (nonatomic, strong) NSMutableArray *sections;
@property (nonatomic, strong) NSMutableArray <HEIMMessageModel *>*dataSource;

@property (nonatomic, strong) GDFormModel *formModel;
//@property (nonatomic, strong) HEOldPelOrgModel *details;

@property (nonatomic, assign) NSInteger pageNum;
@property (nonatomic, assign) NSInteger pageSize;
@property (nonatomic, strong) HEIMForward *imDataForward;
@property(nonatomic, assign) BOOL fristInto;

@property (nonatomic, strong) HETeamModel *teamModel;

@property (nonatomic, strong) NSString *userIdCrad;
@property (nonatomic, strong) NSMutableArray <HEIMKitInfo *> *teamUsers;


@property (nonatomic, strong) HEChatBar *chatBar;

/*!
 * 发送消息时，会置YES
 * 输入框高度变更，比如输入文字换行、切换到 More、Face 页面、键盘弹出、键盘收缩
 */
@property (nonatomic, assign) BOOL allowScrollToBottom;

@property (nonatomic, strong) HEIMSession *session; /// 当前会话
@property (nonatomic, strong) UIView *notifBarView;
@property (nonatomic, strong) UILabel *notifTitleLb;

@end

@implementation HEIMGroupViewController


- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [[IQKeyboardManager sharedManager] setEnable:YES];
    [[HEMediaManager sharedManager] stopPlay];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[IQKeyboardManager sharedManager] isEnabled];
    [[IQKeyboardManager sharedManager] setEnable:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.chatBar close];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.chatBar open];
}

- (void)dealloc {
    [[HESocketManager sharedManager] removeDelegate:self];
    [HEChatManager sharedManager].delegate = nil;
}

- (void)initSession {
    _session = [HEIMSession session:_teamId type: HEIMSessionTypeTeam];
    [[HEIMConversationManager sharedManager] registeSession: _session];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = KWhiteColor;
    HEIMKitInfo *receiveInfo = [[HEIMKit sharedKit] infoByUser:_teamId];
    self.title = receiveInfo.showName;
    
    [self setupNavMenu];
    
    [self initSession];
    
    [[HESocketManager sharedManager] addDelegate:self];
    [HEChatManager sharedManager].delegate = self;
    
    [[HEChatManager sharedManager] setupEmitKey:@"groupRoomSendMsg"];
    
    
    _pageNum = 1;
    _pageSize = 20;
    _fristInto = YES;

    [self.view addSubview:self.tableView];
    
    // 获取群用户
    [self loadTeamUsersData];

    
    [self initInputView];
    
    [self initCell];
    
    [self setupCahceData];
    
    [self loadData];
    [self loadNotifData];
    [[HEChatManager sharedManager] sendQueueIMMassage];
}

- (void)setupNavMenu {
    KWeakSelf
    [self zx_setRightBtnWithImgName:@"menu" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
        HEIMGroupDetailsViewController *vc = [HEIMGroupDetailsViewController new];
        vc.session = weakSelf.session;
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

- (void)setupCahceData {
    [self.dataSource addObjectsFromArray: [[HEChatManager sharedManager] getIMCacheWithSession: _session]];
}

- (void)configSessionUserInfo {
}

- (void)initInputView {
    if (!_isExprie) {
        [self.view addSubview:self.chatBar];
        [self.chatBar open];
        
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(ZXNavBarHeight);
            make.left.and.width.equalTo(self.view);
            make.bottom.equalTo(self.chatBar.mas_top);
        }];
        [self.chatBar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.equalTo(self.view);
            make.height.mas_greaterThanOrEqualTo(@(kLCCKChatBarMinHeight));
            make.bottom.equalTo(self.view);
        }];
        
    }else {
        self.tableView.frame = CGRectMake(0, ZXNavBarHeight, KScreenWidth, KScreenHeight - ZXNavBarHeight - KSafeTabbarHeight);
    }
}

- (void)initCell {
    
    _sections = @[].mutableCopy;
    _dataSource = @[].mutableCopy;
    
    NSMutableArray *classArr = [NSMutableArray array];
    
    //
    GDFiterCellModel *textModel = [GDFiterCellModel new];
    textModel.cellKlass = HEIMTextCell.class;
    
    GDFiterCellModel *imageModel = [GDFiterCellModel new];
    imageModel.cellKlass = HEIMImageViewCell.class;
    
    GDFiterCellModel *audioModel = [GDFiterCellModel new];
    audioModel.cellKlass = HEIMAudioCell.class;
    
    GDFiterCellModel *sysInfoModel = [GDFiterCellModel new];
    sysInfoModel.cellKlass = HEIMRoomInAndoutCell.class;
     
    // 添加的时候注意顺序，暂未对顺序做处理
    classArr = @[textModel, imageModel, audioModel].mutableCopy;
    
    for (GDFiterCellModel *model in classArr) {
        NSString *cellIdOwner = [NSString stringWithFormat:@"%@_%@_%@",NSStringFromClass(model.cellKlass), HECellIdentifierOwnerSelf, HECellIdentifierGroup];
        NSString *cellIdOwnerOther = [NSString stringWithFormat:@"%@_%@_%@",NSStringFromClass(model.cellKlass), HECellIdentifierOwnerOther, HECellIdentifierGroup];
        [self.tableView registerClass:model.cellKlass forCellReuseIdentifier: cellIdOwner];
        [self.tableView registerClass:model.cellKlass forCellReuseIdentifier: cellIdOwnerOther];
    }
    
    [self.tableView registerClass:sysInfoModel.cellKlass forCellReuseIdentifier: [NSString stringWithFormat:@"%@_%@_%@",NSStringFromClass(sysInfoModel.cellKlass), HECellIdentifierSystem, HECellIdentifierGroup]];

}

- (void)loadTeamUsersData {
    _teamUsers = [NSMutableArray array];
    __weak typeof(self) weakself = self;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:_teamId forKey:@"groupId"];
     
    [WOAFNetWorkingHandle GETWithBaseUrl:KServerUrl suffixUrl:KqueryGroupMembers parameters:dict success:^(id  _Nonnull responseObject) {
        NSLog(@"response：  %@", [responseObject mj_JSONString]);

        HEArrayResponse *response = [HEArrayResponse mj_objectWithKeyValues:responseObject];
        NSArray * users = [HEIMGroupMemberModel mj_objectArrayWithKeyValuesArray:response.data];
        
        for (HEIMGroupMemberModel *user in users) {
            HEIMKitInfo *doc = [HEIMKitInfo new];
            doc.infoId = user.id;
            doc.showName = user.name;
            doc.avatarUrlString = user.portrait;
            doc.memberType = user.memberType;
            doc.avatarImage = user.memberType == HEIMGroupMemberTypeGroupMaster || user.memberType == HEIMGroupMemberGroupWorker ? IMAGE_NAMED(@"hmang") : IMAGE_NAMED(@"defualt_icon");

            [self.teamUsers addObject:doc];
            [[HEIMKit sharedKit] registeUserInfo:doc];
        }
    } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)loadData {
    
    HEPageRequest *req = [HEPageRequest new];
    req.pageNum = _pageNum;
    req.pageSize = _pageSize;
    [req addParmas: _teamId key:@"doctor_id"];
    
    [WOAFNetWorkingHandle POSTNoHUDWithBaseUrl:KServerUrl suffixUrl:KImInfo parameters:req success:^(id  _Nonnull responseObject) {
        NSLog(@"response：  %@", [responseObject mj_JSONString]);
        HEArrayResponse *response = [HEArrayResponse mj_objectWithKeyValues:responseObject];
        if (response.success) {
            
            NSArray <HEDocImMsgModel *> *msgList = [HEDocImMsgModel mj_objectArrayWithKeyValuesArray: response.data];
            NSMutableArray *imList = @[].mutableCopy;
            for (HEDocImMsgModel *model in msgList) {
                HEIMInfoEntity *entitiy = [HEIMInfoEntity new];
                entitiy.id = model.id;
                entitiy.from = model.from;
                entitiy.from_id = model.from_id;
                entitiy.to = model.to; // 这里必须这么写
                entitiy.cmd = model.cmd;
                entitiy.create_date = model.create_date;
                entitiy.chatType = model.chatType;
                entitiy.msgType = model.msgType;
                entitiy.message_type = model.message_type;
                entitiy.content = model.content;
                [imList addObject:entitiy];
            }

            NSArray <HEIMMessageModel *> *endMsgs = [HEIMForward transformIMModel:imList];
            if (msgList.count > 0) {
                self.pageNum += 1;
            }
            [self.tableView.mj_header endRefreshing];

            if (self.fristInto) {
                NSRange range = NSMakeRange(0, endMsgs.count);
                NSIndexSet *nsindex = [NSIndexSet indexSetWithIndexesInRange:range];
                [self.dataSource insertObjects:endMsgs atIndexes:nsindex];
                [self.tableView reloadData];
                [self scrollToBottom];
            }else {
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                    NSMutableArray *messages = [NSMutableArray arrayWithArray: endMsgs];
                    [messages addObjectsFromArray:self.dataSource];
                    NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:endMsgs.count];
                    [endMsgs enumerateObjectsUsingBlock:^(id message, NSUInteger idx, BOOL *stop) {
                        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0];
                        [indexPaths addObject:indexPath];
                    }];
                    dispatch_async(dispatch_get_main_queue(),^{
                        CGSize beforeContentSize = self.tableView.contentSize;
                        BOOL animationEnabled = [UIView areAnimationsEnabled];
                        if (animationEnabled) {
                            [UIView setAnimationsEnabled:NO];
                            [self.tableView beginUpdates];
                            self.dataSource = [messages mutableCopy];
                            [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
                            [self.tableView reloadData];
                            [self.tableView endUpdates];
                            CGSize afterContentSize = self.tableView.contentSize;
                            CGPoint afterContentOffset = self.tableView.contentOffset;
                            CGPoint newContentOffset = CGPointMake(afterContentOffset.x, afterContentOffset.y + afterContentSize.height - beforeContentSize.height);
                            [self.tableView setContentOffset:newContentOffset animated:NO] ;
                            [UIView setAnimationsEnabled:YES];
                        }
                    });
                });
            }
        }
    } failure:^(NSError * _Nonnull error) {
        [self.tableView.mj_header endRefreshing];
    }];
}

 
- (void)loadNotifData {

    HEPageRequest *request = [[HEPageRequest alloc] init];
    request.pageNum = 1;
    request.pageSize = 1;
    request.queryParams = @{}.mutableCopy;
    [request addParmas:_session.sessionId key:@"chatGroupId"];

    [WOAFNetWorkingHandle POSTWithBaseUrl:KServerUrl suffixUrl: KlistGroupNotice parameters:request success:^(id  _Nonnull responseObject) {
        HEPageResponse *response = [HEPageResponse mj_objectWithKeyValues:responseObject];
        NSMutableArray *notifs = @[].mutableCopy;
        [notifs addObjectsFromArray:[HEIMGroupNotifModel mj_objectArrayWithKeyValuesArray: response.data.list]];
        [self setupNotifView: notifs];
    } failure:^(NSError * _Nonnull error) {
    }];
}

- (void)setupNotifView:(NSMutableArray *)notifs {
    if (notifs.count > 0) {
        HEIMGroupNotifModel *model = notifs.firstObject;
        NSDate *exprie = [NSDate stringToDate: model.gmt_create formaterMode: NSDateFormaterModeDay]; //
        NSDate *nowDate = [NSDate dateToDate:[NSDate date] formaterMode: NSDateFormaterModeDay];
        NSInteger valid = [NSDate compareOneDate:nowDate withAnotherDate:exprie];
        if (!valid) {
            self.notifBarView.hidden = NO;
            [self.tableView setContentInset:UIEdgeInsetsMake(60, 0, 0, 0)];
            _notifTitleLb.text = model.notice_title;
            return;
        }
    }
    self.notifBarView.hidden = YES;
    [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}

#pragma mark -

- (void)scrollToBottom
{
    [self.tableView layoutIfNeeded];
    CGFloat yOffset = 0; //设置要滚动的位置 0最顶部 CGFLOAT_MAX最底部
    if (self.tableView.contentSize.height > self.tableView.bounds.size.height) {
        yOffset = self.tableView.contentSize.height - self.tableView.bounds.size.height;
    }
    [self.tableView setContentOffset:CGPointMake(0, yOffset) animated: !self.fristInto];
    
    self.fristInto = NO;
}

#pragma mark - UITableViewDataSource
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    HEIMMessageModel *imModel = self.dataSource[indexPath.row];

    HEIMMessageCell *cell = [_tableView dequeueReusableCellWithIdentifier: imModel.cellIdentifier];
    cell.delegate = self;
    [cell configCellWithModel: imModel];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HEIMMessageModel *imModel = self.dataSource[indexPath.row];

 
  return [tableView fd_heightForCellWithIdentifier: imModel.cellIdentifier cacheByIndexPath:indexPath configuration:^(MCTableBaseCell *cell) {
      [cell configCellWithModel: imModel];

   }];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.chatBar endInputing];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.chatBar endInputing];
}

#pragma mark - HEChatBarDelegate
- (void)chatBarFrameDidChange:(HEChatBar *)chatBar shouldScrollToBottom:(BOOL)shouldScrollToBottom {
    [UIView animateWithDuration:LCCKAnimateDuration animations:^{
        [self.tableView.superview layoutIfNeeded];
        self.allowScrollToBottom = shouldScrollToBottom;
        [self scrollToBottomAnimated:NO];
        
//        [self scrollToBottom];

    } completion:nil];
}

- (void)scrollToBottomAnimated:(BOOL)animated {
    if (!self.allowScrollToBottom) {
        return;
    }
    NSInteger rows = [self.tableView numberOfRowsInSection:0];
    if (rows > 0) {
        dispatch_block_t scrollBottomBlock = ^ {
            [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rows - 1 inSection:0]
                                  atScrollPosition:UITableViewScrollPositionBottom
                                          animated:animated];
        };
        if (animated) {
            //when use `estimatedRowHeight` and `scrollToRowAtIndexPath` at the same time, there are some issue.
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                scrollBottomBlock();
            });
        } else {
            scrollBottomBlock();
        }
        
    }
}

- (void)newScrollToBottomAnimated:(BOOL)animated {
    if (!self.allowScrollToBottom) {
        return;
    }
    NSInteger rows = [self.tableView numberOfRowsInSection:0];
    if (rows > 0) {
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rows - 1 inSection:0]
                              atScrollPosition:UITableViewScrollPositionBottom
                                      animated:animated];
    }
}

#pragma mark - HEChatBarDelegate
- (void)sendMessage:(HEIMMessageModel *)message {
    [self.dataSource addObject:message];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
        [self scrollToBottom];
    });
    [[HEChatManager sharedManager] sendMessage:message];
}

#pragma mark - HEChatManagerDelegate
- (void)sendMessageHandler:(HEIMMessageModel *)message {
    DLog(@"aa")
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    });
}

#pragma mark - HESocketManagerDelegate
- (void)onRecvMessages:(HEIMMessageModel *)message {
    UserInfo *user = [UserManager sharedUserManager].curUserInfo;
    if ([_teamId isEqualToString: message.message.to] &&
        ![message.message.from isEqualToString: user.id]) {
        
        [self.dataSource addObject:message];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
            [self scrollToBottom];
        });
    }
}

- (void)loginSuccessHandler {
    [[HEChatManager sharedManager] sendQueueIMMassage];
}

- (void)onGroupMemberUpdate:(NSDictionary *)model {
    UserInfo *user = [UserManager sharedUserManager].curUserInfo;
    NSString *groupId = model[@"groupId"];
    NSString *usid = model[@"usid"];
    NSInteger type = [(NSNumber *)model[@"type"] integerValue];
    
    if ([self.session.sessionId isEqualToString:groupId]) {
        // 0 踢人 1 加人
        if ([user.id isEqualToString: usid] && type == 0) {
            [WOAlert alertShowTitle:@"系统提示" message:@"您已被移除群聊" cancelButtonTitle:@"确定" otherButtonTitles:nil block:^(NSInteger buttonIndex) {
                [self.navigationController popViewControllerAnimated:YES];
            }];
            return;
        }
        [self loadTeamUsersData];
    }
}

- (void)onGroupCreateAndDelUpdate:(NSDictionary *)model {
    NSString *groupId = model[@"groupId"];
    NSInteger type = [(NSNumber *)model[@"type"] integerValue];

    // 0 删除群 1 加群
    if ([self.session.sessionId isEqualToString:groupId] && type == 0) {
        [WOAlert alertShowTitle:@"系统提示" message:@"该群已解散" cancelButtonTitle:@"确定" otherButtonTitles:nil block:^(NSInteger buttonIndex) {
            [self.navigationController popViewControllerAnimated:YES];
        }];
    }
}

#pragma mark - HEIMMessageCellDelegate
- (void)onTapMessage:(HEIMMessage *)message {
    if (message.type == HEIMMessageTypeAudio) {
        [[HEMediaManager sharedManager] playByMessage: message];
    }else if (message.type == HEIMMessageTypeGroupNotif) {
        [self toNotifPage];
    }
}

- (void)onTapAvatar:(HEIMMessage *)message {
    if (!message.isOwn) {
        HEDoctorMainPageViewController *vc = [HEDoctorMainPageViewController new];
        vc.userId = message.from;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)onLongPressAvatar:(HEIMMessage *)message {
    if (!message.isOwn) {
        [self.chatBar addATPerson: [[HEIMKit sharedKit] infoByUser:message.from] isLong:YES];
    }
}

#pragma mark - UITableViewDelegate
#pragma lazy load
- (GDFormModel *)formModel {
    if (!_formModel) {
        _formModel = [[GDFormModel alloc] init];
        _formModel.proxyVC = self;
    }
    return _formModel;
}

- (HEIMForward *)imDataForward {
    if (!_imDataForward) {
        _imDataForward = [HEIMForward new];
    }
    return _imDataForward;
}

- (NSMutableArray<HEIMMessageModel *> *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (GDTableView *)tableView {
    if (!_tableView) {
        _tableView = [[GDTableView alloc] initWithFrame:CGRectMake(0, ZXNavBarHeight , KScreenWidth, KScreenHeight - ZXNavBarHeight - 49 - KSafeTabbarHeight) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.scrollsToTop = YES;
        _tableView.tableHeaderView = [[UIView alloc] init];
        _tableView.tableFooterView = [[UIView alloc] init];

        _tableView.backgroundColor = KHexColor(@"f6f6f6");
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
            [UITableView appearance].sectionHeaderTopPadding = 0;
        } else {
            // Fallback on earlier versions
        }
        

        HEActivityHeader *header = [HEActivityHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
        _tableView.mj_header = header;
        
    }
    return _tableView;
}

#pragma mark - getter

- (HEChatBar *)chatBar {
    if (!_chatBar) {
        _chatBar = [[HEChatBar alloc] initWithFrame:CGRectZero type: _modelType];
        _chatBar.delegate = self;
        _chatBar.teamUserList = _teamUsers;
        _chatBar.session = _session;
        [self.view addSubview: _chatBar];
        [self.view bringSubviewToFront:_chatBar];
    }
    return _chatBar;
}
 
- (UIView *)notifBarView {
    if (!_notifBarView) {
        
        UIView *warp = [[UIView alloc] initWithFrame:CGRectMake(15, ZXNavBarHeight + 10, KScreenWidth - 30, 50)];
        warp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
        warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
        warp.layer.shadowOffset = CGSizeMake(0,5);
        warp.layer.shadowOpacity = 1;
        warp.layer.shadowRadius = 12;
        [self.view addSubview:warp];
        _notifBarView = warp;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toNotifPage)];
        [warp addGestureRecognizer:tap];
        
        
        _notifTitleLb = [UILabel new];
        _notifTitleLb.text = @"-";
        _notifTitleLb.font = DYFont(16);
        _notifTitleLb.numberOfLines = 1;
        _notifTitleLb.textColor = KHexColor(@"#5e5e5e");
        [warp addSubview:_notifTitleLb];
        
        UIImageView *_iconView = [UIImageView new];
        _iconView.contentMode = UIViewContentModeScaleAspectFill;
        _iconView.image = IMAGE_NAMED(@"go_gray");
        _iconView.layer.masksToBounds = YES;
        _iconView.layer.cornerRadius = 5;
        [warp addSubview:_iconView];
                
        [_notifTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(warp).mas_offset(0);
            make.left.equalTo(warp).mas_offset(15);
            make.right.equalTo(_iconView.mas_left).mas_offset(-15);
            make.bottom.equalTo(warp).mas_offset(-0);
        }];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(warp);
            make.right.equalTo(warp).mas_offset(-15);
            make.width.mas_offset(8);
            make.height.mas_offset(12);
        }];
    }
    return _notifBarView;
}

- (void)toNotifPage {
    HEIMNotificationViewController *vc = [HEIMNotificationViewController new];
    vc.session = self.session;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
